package cn.hpclub.server.controller.admin.campus;/**
 * Created by zenghl on 2016/8/23.
 */

import cn.hpclub.server.controller.admin.BaseAdminController;
import cn.hpclub.server.model.campus.BroadbandOpenOrder;
import cn.hpclub.server.service.campus.BroadbandOpenOrderService;
import cn.hpclub.server.service.recommend.RecommendService;
import cn.hpclub.server.util.ExcelRenderUtil;
import cn.hpclub.server.util.InterfaceUtil;
import cn.hpclub.server.util.ObjectUtil;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @FileName BroadbandOpenOrderController
 * @Author zhl
 * @Description BROADBANDOPENORDERADMIN/list
 * @Date 2016-08-23 11:59
 * @CopyRight ZTE Corporation
 */
public class BroadbandOpenOrderAdminController extends BaseAdminController<BroadbandOpenOrder> {
    private static final String ORG_LIST = "orgList";
    private static final String ORG_ID   = "org_id";
    private static Logger logger = LoggerFactory.getLogger(BroadbandOpenOrderAdminController.class);

    private int initOrgTree(){
        List<Map.Entry<String, String>> orgList = InterfaceUtil.getOrgList();
        if(orgList.size() > 0){
            /* 机构树可用 */
            setAttr(ORG_LIST, orgList);
            return Integer.parseInt(orgList.get(0).getValue());
        } else{
            return 0;
        }
    }
    public void list(){
        int defaultOrgId = initOrgTree();
        ConcurrentHashMap<String, String> searchInfo = getSearchInfo();
        if(searchInfo.get(ORG_ID) == null){
            searchInfo.put(ORG_ID, String.valueOf(defaultOrgId));
        }
        setAttr(ORG_ID, searchInfo.get(ORG_ID));
        findByPageForSearch(BroadbandOpenOrderService.service.getSqlHead(), BroadbandOpenOrderService.service.getSqlExceptSelect(searchInfo));
        render("/admin/broadband_open_order_detail.tpl");
    }

    public void exportAll(){
        ConcurrentHashMap<String, String> searchInfo = getSearchInfo();
        int defaultOrgId = initOrgTree();
        if(searchInfo.get(ORG_ID) == null){
            searchInfo.put(ORG_ID, String.valueOf(defaultOrgId));
        }
        SXSSFWorkbook workbook = new BroadbandOpenOrderService().service.getExcel(searchInfo);
        render(new ExcelRenderUtil(workbook, "宽带开户"));
    }

}
